
import Dates from '@mods/utils/date';


export default {
    filters: {
        transferText(val = '', text = "", list = [], key = "id") {
            if (val === '' || !list) return '';
            let type = typeOf(list), data = {}
            if (type === 'array') {
                data = list.filter(item => {
                    return item[key] == val;
                })[0] || {};
            } else if (type === 'object') {
                data = list;
            }
            if (text.indexOf('%') == -1) return data[text];//兼容老模块

            return text.replace(/\%([A-Za-z0-9_-]+)\%/g, function (match, reg, index, str) {
                return data[reg] || ''
            })
        }
    },
    methods: {
        handleDateFormat(date, format) {
            return Dates.stringify(date, format);
        },
    },
}